home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9794 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  40 lines

  1. Newsgroups: comp.lang.c++
  2. Path: presby.edu!jtbell
  3. From: jtbell@presby.edu (Jon Bell)
  4. Subject: Re: Class
  5. Message-ID: <Dnr1Bv.Jy9@presby.edu>
  6. Date: Mon, 4 Mar 1996 15:21:30 GMT
  7. References: <4hchoh$ngh@nova.umuc.edu> <DnpEHt.BH3@presby.edu> <HEYDENJ.96Mar4095800@bothrops.natlab.research.philips.com>
  8. Organization: Presbyterian College, Clinton, South Carolina USA
  9.  
  10.  Heijden van der J. <heydenj@bothrops.natlab.research.philips.com> wrote:
  11. >The #ifndef / #define / #endif is used to prevent a single header to be
  12. >included more then once (a header file might already be included in one of
  13. >the other header files you include. 
  14.  
  15. Yes, this trick will prevent any function definitions in the header file 
  16. from being compiled more than once, *provided* that the main program has 
  17. only one source file that #includes EmpRecords.h.
  18.  
  19. But if there are two or more source files, and both of them #include 
  20. EmpRecords.h, for example:
  21.  
  22.     g++ foo.cc -c
  23.     g++ bar.cc -c
  24.     g++ foo.o bar.o -o foobar
  25.  
  26. or even just
  27.  
  28.     g++ foo.cc bar.cc -o foobar
  29.  
  30. (I'm assuming that EmpRecords.cc has already been compiled.)
  31.  
  32. If both foo.cc and bar.cc #include EmpRecords.h, and EmpRecords.h 
  33. contains actual function definitions, then those functions will be 
  34. compiled twice and you will probably get a warning from the linker about 
  35. "duplicate symbols" or some such thing.
  36.  
  37. -- 
  38. Jon Bell <jtbell@presby.edu>                        Presbyterian College
  39. Dept. of Physics and Computer Science        Clinton, South Carolina USA
  40.